package utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class DBUtil {
    private static String Driver;
    private static String URL;
    private static String USERNAME;
    private static String PASSWORD;

    static {
    	LoadPFromP p = new LoadPFromP();
            Driver = p.getdbProperty("driver");
            URL = p.getdbProperty("url");
            USERNAME = p.getdbProperty("username");
            PASSWORD = p.getdbProperty("password");
    }

    public static Connection getConnection() {
        Connection conn = null;
        try {
            Class.forName("DB_Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("DBUtil2加载驱动出错");
            e.printStackTrace();
        }

        try {
            conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
        } catch (SQLException e) {
            System.out.println("DBUtil2获取连接出错");
            e.printStackTrace();
        }
        return conn;

    }

	public static void closeConnection(ResultSet rs,PreparedStatement ps,Connection conn){
		if(rs!=null){
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(ps!=null){
			try {
				ps.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(conn!=null){
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}	
			
		}		
	}

}
